package com.adcc.ags.gms.mq.service;

import com.adcc.ags.gms.core.entity.GWLogLevel;
import com.adcc.ags.gms.core.util.LogFactory;
import com.adcc.ags.gms.core.util.MQFactory;
import com.adcc.ags.gms.mq.vo.TopicVO;
import com.adcc.utility.mq.entity.ibm.IBMTopic;
import com.google.common.base.Optional;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 会话服务层
 */
@Service("TopicService")
public class TopicServiceImpl implements TopicService {

    // 常量
    private final static String TOPIC_NAME = "T.*";

    @Autowired
    private LogFactory log;

    @Autowired
    private MQFactory mqFactory;

    @Override
    public Optional<List<TopicVO>> findAllTopic() {
        try{
            List<TopicVO> result = Lists.newArrayListWithExpectedSize(1000);
            List<IBMTopic> list = mqFactory.getSourceMQM().findTopic(TOPIC_NAME);
            if(list != null && list.size() > 0){
                for(IBMTopic topic : list){
                    TopicVO vo = new TopicVO(topic);
                    result.add(vo);
                }
            }
            return Optional.of(result);
        }catch (Exception ex){
            log.error(QueueService.class,"MQ", GWLogLevel.SERIOUS_ALARM, "获取会话信息异常", ex);
            return Optional.absent();
        }
    }
}
